package com.fanhang.samples.spring.sql2o.common;

import javax.sql.DataSource;

import org.sql2o.Connection;
import org.sql2o.Query;
import org.sql2o.Sql2o;

public class DefaultSql2oSession implements Sql2oSession {

	private DataSource dataSource;
	
	public DefaultSql2oSession(DataSource dataSource) {
		this.dataSource = dataSource;
	}
	
	@Override
	public Sql2o getSql2o() {
		return new Sql2o(this.dataSource);
	}

	@Override
	public Connection getConnection() {
		return getSql2o().beginTransaction();
	}

	@Override
	public Query createQuery(String sql) {
		return getConnection().createQuery(sql);
	}

}
